package com.zhang.network;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;

/**
 * @author zhangshuaiyin
 */
@Slf4j
@SpringBootApplication
@MapperScan("com.zhang.network.mapper")
public class NetworkApplication {
    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext application = SpringApplication.run(NetworkApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        port = port == null ? "8080" : port;
        String path = env.getProperty("server.servlet.context-path");
        path = path == null ? "" : path;
        String url = "http://localhost:" + port + path + "/hello";
        log.info("\n----------------------------------------------------------\n\t" +
                "Application Network is running! Access URLs:\n\t" +
                "本地访问地址: \thttp://localhost:" + port + path + "/\n\t" +
                "外部访问地址: \thttp://" + ip + ":" + port + path + "/\n\t" +
                "Swagger文档: \thttp://" + ip + ":" + port + path + "/swagger-ui.html\n" +
                "----------------------------------------------------------");

        String os = System.getProperty("os.name");
        // 默认为 windows时才自动打开页面
        /*if (StringUtils.containsIgnoreCase(os, "windows")) {
            //使用默认浏览器打开系统登录页
            try {
                Runtime.getRuntime().exec("cmd /c start " + url);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }*/
    }
}
